import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_stort/page/home_page.dart';
import 'package:flutter_stort/page/person_page.dart';
import 'package:flutter_stort/page/search_page.dart';
import 'package:flutter_stort/page/shopping_cart_page.dart';

import 'package:badges/badges.dart';

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  var _listPage = [HomePage(), SearchPage(), ShoppingCartPage(), PersonPage()];
  int _currentIndex = 0;
  void _selectPosition(int position) {
    setState(() {
      _currentIndex = position;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _listPage[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        onTap: _selectPosition,
        currentIndex: _currentIndex,
        fixedColor: Colors.blue,
        items: [
          BottomNavigationBarItem(
            icon: Icon(CupertinoIcons.home,size: 22,),
            label: "首页",
          ),
          BottomNavigationBarItem(
            icon: Icon(CupertinoIcons.search,size: 22,),
            label: "发现",
          ),
          BottomNavigationBarItem(
            icon: Badge(
              showBadge: false,
              badgeContent: Text("0",style: TextStyle(color: Colors.white,fontSize: 12),),
              child:  Icon(CupertinoIcons.shopping_cart,size: 22,),
            ),
            label: "购物车",
          ),
          BottomNavigationBarItem(
            icon: Icon(CupertinoIcons.profile_circled,size: 22,),
            label: "我的",
          ),
        ],
      ),
    );
  }
}
